home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Windows Selection / Windows Selection 1.iso / Graphics / Formula Graphics Multimedia System / ARRAYS.SXT < prev    next >
Encoding:
Text File  |  1996-03-18  |  2.0 KB  |  84 lines

  1. //////////////////////////
  2. // Harrow Software 1996
  3. // Bitmap examples
  4.  
  5. ///////////////////////////
  6. // (1) - Floating point arrays
  7.  
  8. // A new floating point array with 4x4 elements can be allocated
  9.  
  10. my_array = new float[4][4]
  11.  
  12. // These element will be assigned random values between 0 and 100
  13.  
  14. for x,y = 0,0 to 3,3
  15.     my_array[x][y] = rnd 100
  16.  
  17. // Get the size of the array
  18.  
  19. size_of_1st_dimension = my_array(0)
  20. size_of_2nd_dimension = my_array(1)
  21.  
  22. for x,y = 0,0 to size_of_1st_dimension-1, size_of_2nd_dimension-1
  23.     message my_array[x][y]
  24.  
  25. ///////////////////////////
  26. // (2) - Byte Arrays
  27.  
  28. // This new byte array will be allocated with 256 red, green and
  29. //  blue values
  30.  
  31. my_palette = new byte[256][3]
  32.  
  33. // This palette can then be filled with a scale of grey colors
  34.  
  35. for n = 0 to 255
  36.     my_palette[n][0] = n,n,n
  37.  
  38. // Strings are stored as byte arrays. This assignment will
  39. //  allocate a byte array large enough to store the length of the
  40. //  string plus one for the terminating zero.
  41.  
  42. $my_string = "This is a string"
  43.  
  44. // The ansi values of each character in the string can be
  45. //  shown. The ansi value of 'A' is 65.
  46.  
  47. n = 0
  48. while my_string[n]
  49.     message my_string[n], " = '", strchr my_string[n], "'"
  50.     n++
  51.  
  52. ///////////////////////////
  53. // (3) - Text files
  54.  
  55. // A text file can be loaded from disk into a byte array and
  56. //  assigned to a handle. A text file can also be saved to disk
  57.  
  58. load "example.txt" byte my_text
  59. save "example.txt" byte my_text
  60.  
  61. // You can search the contents of a text array for any
  62. //  matching string. The search will start from the given
  63. //  position in the array
  64.  
  65. my_pos = 0
  66. my_pos = parse my_text[my_pos] for "some string"
  67. if my_pos == ERROR
  68.     message "String not found"
  69.  
  70. // A text array can be broken down into words and numbers. Each
  71. //  word and number in this file will be displayed in the result
  72. //  window
  73.  
  74. my_pos = 0
  75. while my_pos != ERROR
  76.     my_pos = parse my_text[my_pos] to $my_string
  77.     if my_pos != ERROR then message $my_string
  78. message "End of text"
  79.  
  80.  
  81.  
  82.  
  83.  
  84.